package ru.nosport.matrixaria.modules.user.rmreg.client;

import ru.nosport.matrixaria.modules.common.AppServerProcess;
import ru.nosport.matrixaria.modules.core.rmreg.RemoteModuleRegistration;
import ru.nosport.matrixaria.modules.user.rmreg.server.Cushion;
import ru.nosport.matrixaria.core.MessageHandler;
import ru.nosport.matrixaria.core.MessageHandlerException;
import ru.nosport.matrixaria.core.ModuleShortcut;
import ru.nosport.matrixaria.core.CoreVars;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.util.ResourceBundle;

/**
 * User: Victor Fabrichenko
 * Date: 28.04.2009
 * Time: 16:27:26
 * 
 */
public class NeedleApp implements Needle, AppServerProcess{
	private String resultString;
	static public final String testPhrase = "to_thread_needle.";
	static public final String testName = "NeedleRemoteTest";
	private RemoteModuleRegistration rmreg;

	public NeedleApp(Configuration _conf){

	}

	public String toThreadNeedle(String _color) {
		return testPhrase + _color;
	}

	public String getRezForTest() {
		return this.resultString;
	}

	public boolean moduleStart() throws Exception {

		this.rmreg = (RemoteModuleRegistration)MessageHandler.getModule("RemoteModuleRegistrationClient");

		ModuleShortcut msh = MessageHandler.getOnflyModule("NeedleRemoteTest");//new ModuleShortcut(xml, 0, "ru.nosport.matrixaria.modules.remote.RemoteModule");

		this.rmreg.registration(msh);

		Cushion cushion = (Cushion) MessageHandler.getModule("CushionClient");
		this.resultString = cushion.stuckNeedle(testName);

		MessageHandler.releaseModule("CushionClient", cushion);

		return true;
	}

	public boolean moduleStop() {
		try {
			MessageHandler.releaseModule("RemoteModuleRegistrationClient", this.rmreg);
		} catch (MessageHandlerException e) {
			e.printStackTrace();
		}

		return true;
	}

	public boolean isModuleRunning() {
		return false;
	}

	public String moduleStat() {
		return null;
	}
}
